<template>
  <el-card shadow="hover">
    <el-form :model="formData" label-width="100px">
      <el-form-item label="公司介绍" prop="aboutCompany">
        <Editor v-model="formData.aboutCompany" height="300px"/>
      </el-form-item>
      <el-form-item label="电话联系" prop="aboutContactUs">
        <el-input v-model="formData.aboutPhone" maxlength="50" show-word-limit clearable/>
      </el-form-item>
      <el-form-item label="邮箱联系" prop="aboutContactUs">
        <el-input v-model="formData.aboutEmail" maxlength="50" show-word-limit clearable/>
      </el-form-item>
      <el-form-item label="安卓版本" prop="aboutAndroid">
        <el-input v-model="formData.aboutAndroid" maxlength="30" show-word-limit clearable/>
      </el-form-item>
      <el-form-item label="安卓更新地址" prop="androidLink">
        <el-input v-model="formData.androidLink"  show-word-limit clearable/>
      </el-form-item>
      <el-form-item label="iOS版本" prop="aboutIos">
        <el-input v-model="formData.aboutIos" maxlength="30" show-word-limit clearable/>
      </el-form-item>
      <el-form-item label="iOS更新地址" prop="iosLink">
        <el-input v-model="formData.iosLink" show-word-limit clearable/>
      </el-form-item>
      <el-form-item label="用户协议" prop="userPact">
        <Editor v-model="formData.userPact" height="300px"/>
      </el-form-item>
      <el-form-item label="隐私协议" prop="privacyPact">
        <Editor v-model="formData.privacyPact" height="300px"/>
      </el-form-item>
    </el-form>

    <el-button v-hasPermi="['yxt:assure:update']" type="primary" @click="submit">更 新</el-button>
    <el-button v-hasPermi="['yxt:assure:update']" type="primary" @click="resetForm">重 置
    </el-button>
  </el-card>
</template>

<script lang="ts" setup>
import {useAssureApi} from "@/api/yxt/assure";
import {useMessage} from "@/hooks/web/useMessage";

defineOptions({name: 'YxtAssure'})

const assureApi = useAssureApi();
const message = useMessage();
const {t} = useI18n()
const formData = ref({
  id: undefined,
  aboutCompany: '',
  aboutPhone: '',
  aboutEmail: '',
  aboutAndroid: '',
  androidLink: '',
  aboutIos: '',
  iosLink: '',
  userPact: '',
  privacyPact: ''
})

const getDetail = async () => {
  formData.value = await assureApi.getAssure() || {};
}

const submit = async () => {
  try {
    await message.confirm(t('common.updateMessage'));
    await assureApi.updateAssure(formData.value);
    message.success(t('common.updateSuccess'));
    getDetail();
  } catch {
  }
}


const resetForm = () => {
  getDetail();
}

onMounted(() => {
  getDetail();
})
</script>

